"""
文件打开
文件写入
文件读取
文件关闭
"""
file_path = "/day03/test.txt"
file_obj = open(file_path, 'r')
file_obj = open(file_path, 'w')  # 打开后会清空原有内容
file_obj = open(file_path, 'a')  # 打开后不会清空原有内容

file_obj.close()

# 1.文件读取
file_path = "/day03/test.txt"
file_obj = open(file_path, 'r')

data = file_obj.read()  # 读取全部内容到data
# data = file_obj.read(5)  # 读取最多5个字符到data
print(data)

file_obj.close()

# 2.文件写入
file_path = "/day03/test.txt"
file_obj = open(file_path, 'w')

data = file_obj.read()  # 读取全部内容到data
print(data)

file_obj.close()
